package GUI;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.filechooser.FileNameExtensionFilter;


/**
 *
 * @author Agustin Ramirez Hernandez
 */
public class AdministradorDeArchivos extends JPanel {

    private final JFileChooser fc;
    private File file;
    private String archActual;
     private static FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos de Imagenes", 
             "png","PNG","jpeg","JPEG","JPG","jpj","gif","pgm");

    public AdministradorDeArchivos() throws FileNotFoundException, IOException {
        fc = new JFileChooser();
        fc.setFileFilter(filter);
        fc.setCurrentDirectory(new File("$HOME"));
    }

    public void Abrir() throws FileNotFoundException, IOException {
        int returnVal = fc.showOpenDialog(AdministradorDeArchivos.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            file = fc.getSelectedFile();
            File fil = fc.getSelectedFile();
            this.archActual = fil.getName();
        }
    }
    
    public void Salvar (){
            int returnVal = fc.showSaveDialog(AdministradorDeArchivos.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File fil = fc.getSelectedFile();
                this.archActual=fil.getAbsolutePath();
            }
        }

    public String getArchActual() {
        return archActual;
    }

    public File getFile() {
        return file;
    }
    
}
